<?php

require_once dirname(__FILE__) . '/config.php';
require_once 'SessionDelegate.php';
require_once MOBILEPROXY_SPYC_DIR . '/spyc.php';
require_once MOBILEPROXY_JSPHON_DIR . '/Jsphon.php';

$session =& SessionDelegate::getInstance();
$headers = Spyc::YAMLLoad(MOBILEPROXY_REQUESTHEADERS_YAML);
$array = array('headers' => array());
if (isset($_POST['id'])) {
    $id = (int) $_POST['id'];
    if (!isset($headers[$id])) {
        $id = 0;
    }
    $array['headers'] = $headers[$id]['headers'];
    $session->set('request_headers', $array['headers']);
    /**
     * Initialize pseudo cookie store if request headers are changed.
     */
    $session->set('request_cookies', array());
} elseif ($request_headers = $session->get('request_headers')) {
    $array['headers'] = $request_headers;
} else {
    $array['headers'] = $headers[0]['headers'];
}
header('Content-Type: text/javascript;charset=UTF-8');
echo Jsphon::encode($array);
exit;
